// npx babel-node set_demo01.js

let test01 = function() {
    const s = new Set();

    [2, 3, 5, 4, 5, 2, 2].forEach(x => s.add(x));

    for (let i of s) {
        console.log(i);
    }
};

// test01();

let test02 = function() {
    let _;
    const set = new Set([1, 2, 3, 4, 4]);
    _ = [...set]
    console.log(_)

    const items = new Set([1, 2, 3, 4, 5, 5, 5]);
    _ = items.size;
    console.log(_)

    // const set1 = new Set(document.querySelectorAll('div'));

};

// test02();

let test03 = function() {
    let set = new Set(['red', 'green', 'blue']);

    for (let item of set.keys()) {
        console.log(item);
    }

    console.log('-'.repeat(9));

    for (let item of set.values()) {
        console.log(item);
    }

    console.log('-'.repeat(9));

    for (let item of set.entries()) {
        console.log(item);
    }
}

// test03();

let test04 = function() {
    let set = new Set([1, 4, 9]);
    set.forEach((value, key) => console.log(key + ' : ' + value));
}

// test04()

let test05 = function() {
    let a = new Set([1, 2, 3]);
    let b = new Set([4, 3, 2]);

    // 并集
    let union = new Set([...a, ...b]);
    console.log(union)

    // 交集
    let intersect = new Set([...a].filter(x => b.has(x)));
    console.log(intersect);

    // 差集
    let difference = new Set([...a].filter(x => !b.has(x)));
    console.log(difference)
}

// test05();

let test06 = function() {
    let _;

    const ws = new WeakSet();
    const obj = {};
    const foo = {};

    ws.add(obj);

    _ = ws.has(obj);
    console.log(_);

    _ = ws.has(foo);
    console.log(_);

    ws.delete(obj);
    _ = ws.has(obj);
    console.log(_);
}

test06()




